package com.kevin.testmediaplayer;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Context;

public class MainActivity extends Activity {
	private MediaPlayer mMediaPlayer;
	private AudioManager mAudioManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
	}

	public void onClkStartPlay(View view) {
		mMediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.sctt);
		mMediaPlayer.start();
	}
	
	public void onClkSpeakerMode(View view) {
		// use speakerphone
		mAudioManager.setMode(AudioManager.MODE_IN_CALL);
		mAudioManager.setSpeakerphoneOn(true);
	}
	
	public void onClkInCallMode(View view) {
		// use earpiece
		mAudioManager.setMode(AudioManager.MODE_IN_CALL);
		mAudioManager.setSpeakerphoneOn(false);
	}

	@Override
	protected void onPause() {
		mMediaPlayer.stop();
		mMediaPlayer.release();
		mMediaPlayer = null;
		super.onPause();
	}
	
}
